<template>
  <div v-if="visible" class="message-box-overlay">
    <div class="message-box">
      <div class="message-box-header">
        <slot name="title">提示</slot>
      </div>
      <div class="message-box-content">
        <slot name="content">{{ title }}</slot>
      </div>
      <div class="message-box-footer">
        <el-button
          v-for="(button, index) in buttons"
          :key="index"
          :type="button.type"
          @click="handleButtonClick(button.action)"
        >
          {{ button.text }}
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "MessageBox",
  data() {
    return {
      visible: false,
    };
  },
  props: {
    buttons: {
      type: Array,
      default: () => [
        { text: "取消", action: () => this.close(), type: "" },
        { text: "确定", action: () => this.close(), type: "primary" },
      ],
    },
    title: {
      type: String,
      default: "提示",
    },
  },
  methods: {
    open() {
      this.visible = true;
    },
    close() {
      this.visible = false;
      this.$emit("close");
    },
    handleButtonClick(action) {
      action();
    },
  },
};
</script>

<style lang="scss" scoped>
.message-box-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 99;
}

.message-box {
  background-color: white;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  width: 600px;
  z-index: 100;
}

.message-box-header {
  padding: 20px 20px 0;
  font-size: 18px;
  font-weight: bold;
}

.message-box-content {
  padding: 20px;
}

.message-box-footer {
  padding: 0 20px 20px;
  text-align: right;
}

.message-box-footer {
  .el-button {
    margin-left: 10px;
    /* padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer; */
  }
}
</style>
